<?php
/**
 * Created by PhpStorm.
 * User: Nevena i Milena
 * Date: 2/24/14
 * Time: 12:00 AM
 */

if (isset ($_GET['q'])) {

    $sql="select * from student where ime like '%".$_GET['q']."%' or prezime like '%".$_GET['q']."%'";

    require_once 'Konekcija.php';
    require_once 'Student.php';

    if(!$query = $mysqli->query($sql))
        echo "Greska pri izvodjenju upita" . mysql_error();

    $studenti = array();

    while($row = $query->fetch_object()){
        $student = new Student($row->indeks, $row->ime, $row->prezime, $row->smer, $row->datum_rodjenja);
        array_push($studenti, $student);
    }

    echo json_encode($studenti);

}

?>